Description

I’m going to focus on the Airbnb data in Manhattan for this Assignment.These data were accessed from Inside Airbnb on July 5th, 2020. The version of the data that we will use in this class can be found here.

Data discription

The data set contains NYC airbnb data including type of room, price, location, avaiability etc.

After loading the data, the resulting R data file airbnb contains a single dataframe with 21,963 rows of data on 16 variables:

Map

The map shows the name, location, Price and room type of Airbnb houses in Manhattan.

popupmessage = paste("Name:", as.character(manh_airbnb$name), "<br>",
                     "Room Type:", as.character(manh_airbnb$room_type), "<br>",
                     "Price:", as.character(manh_airbnb$price), "<br>")


manh_airbnb = manh_airbnb %>% mutate(color = "pink")


getColor <- function(manh_airbnb) {
  sapply(manh_airbnb$room_type, function(room_type) {
  if(room_type  == "Private room") {
    "red"
  } else if(room_type  == "Entire home/apt") {
    "lightgreen"
  } else if(room_type  == "Shared room") {
    "lightblue"
  }else {
    "pink"
  } })
}

icons <- awesomeIcons(
  icon = 'ios-close',
  iconColor = 'white',
  library = 'ion',
  markerColor = getColor(manh_airbnb)
)



manh_airbnb %>% 
  leaflet() %>%
  setView(lng = -73.9712, lat = 40.7831, zoom = 12) %>% 
  addTiles() %>%
  addAwesomeMarkers(clusterOptions = markerClusterOptions(),
             popup = popupmessage,icon=icons) %>% 
  addLegend(labels = c("Private room","Entire home/apt","Shared room","Hotel room"), colors = c("red", "lightgreen", "lightblue","pink"))
## Assuming "longitude" and "latitude" are longitude and latitude, respectively